Classes | Defines | Typedefs | Enumerations | Functions

C:/Programming/CodeLite/Codes/LibGL2D/gl2d.h File Reference

A very small and simple PC/MAC/DS rendering lib using the 3d core to render 2D stuff. More...

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <libraries/include/GL/glfw.h>

Go to the source code of this file.

Classes

struct  glImage
 Struct for our GL-Based Images
This is our struct to hold our image attributes. You don't need to worry about this if you use the texture packer. More...

Defines

#define ARGB_A(u)   (((u) >> 24) & 0x000000FF)
#define ARGB_R(u)   (((u) >> 16) & 0x000000FF)
#define ARGB_G(u)   (((u) >> 8) & 0x000000FF)
#define ARGB_B(u)   (((u) >> 0) & 0x000000FF)
#define RGBA(r, g, b, a)   ((a) << 24 | (r) << 16 | (g) << 8 | (b) )
#define GL2D_RGBA(r, g, b, a)   RGBA( b, g, r, a)
 Macro to use for all the color arguments of Easy GL2D primitives.
#define true   1
#define false   0

Typedefs

typedef enum GL2D_FLIP_MODE GL2D_FLIP_MODE
 Enums selecting flipping mode.
typedef enum GL2D_BLEND_MODE GL2D_BLEND_MODE
 Enums selecting Blending/Blitting mode.
typedef struct glImage glImage
 Struct for our GL-Based Images
This is our struct to hold our image attributes. You don't need to worry about this if you use the texture packer.

Enumerations

enum  GL2D_FLIP_MODE { GL2D_FLIP_NONE = 1 << 0, GL2D_FLIP_V = 1 << 1, GL2D_FLIP_H = 1 << 2 }
 

Enums selecting flipping mode.

More...
enum  GL2D_BLEND_MODE {
  GL2D_TRANS = 0, GL2D_SOLID, GL2D_BLENDED, GL2D_GLOW,
  GL2D_ALPHA, GL2D_BLACK
}
 

Enums selecting Blending/Blitting mode.

More...

Functions

void glBegin2D (const int width, const int height)
 Sets up OpenGL for 2d rendering.
Call this before drawing any of GL2D's drawing or sprite functions.
void glEnd2D ()
 Issue this after drawing 2d so that we don't mess the matrix stack.
The compliment of glBegin2D().
void glScreen2D (const int width, const int height, const int mode)
 Initializes GL in 2D mode.
void glScreen2DEx (const int width, const int height, const int mode, const int depthbits, const int stencilbits)
 Initializes GL in 2D mode with more control.
void glClose ()
 Cleans up Easy GL2D. Call this at program end. External texture management is up for the user to clean up.
void glBlendMode (const GL2D_BLEND_MODE mode)
 Sets the default blending/blitting mode.
void glEnableSpriteStencil (const GLuint gl2dcolor, const GLuint gl2dcolor_env, int flag)
 Sets texture environment color Used to draw sprites in a single fill color Very useful for flash/hit animations (1 - (texture image color)) * (glColor color) + (texture image color) * (texture environment color) ie. Pure White Sprites.
void glEnableAntialias (int flag)
void glClearScreen ()
 Clears the GL2D screen buffer.
void glLineGlow (const int x1, const int y1, const int x2, const int y2, const int width, const GLuint color)
 Draws a glowing line.
void glPutPixel (int x, int y, const GLuint color)
 Draws a Pixel.
void glLine (int x1, int y1, int x2, int y2, const GLuint color)
 Draws a Line.
void glLineGradient (int x1, int y1, int x2, int y2, const GLuint color1, const GLuint color2)
 Draws a Line in a gradient color.
void glBox (int x1, int y1, int x2, int y2, const GLuint color)
 Draws a Box.
void glBoxFilled (int x1, int y1, int x2, int y2, const GLuint color)
 Draws a Box filled with a single color.
void glBoxFilledGradient (int x1, int y1, int x2, int y2, const GLuint color1, const GLuint color2, const GLuint color3, const GLuint color4)
 Draws a Box filled with a gradient color.
void glTriangle (int x1, int y1, int x2, int y2, int x3, int y3, const GLuint color)
 Draws a Triangle.
void glTriangleFilled (int x1, int y1, int x2, int y2, int x3, int y3, const GLuint color)
 Draws a Triangle filled with a single color.
void glTriangleFilledGradient (int x1, int y1, int x2, int y2, int x3, int y3, const GLuint color1, const GLuint color2, const GLuint color3)
 Draws a Triangle filled with a gradient color.
void glEllipse (int x, int y, int a, int b, int degrees, const GLuint color)
 Draws a hollow Ellipse.
void glEllipseFilled (int x, int y, int a, int b, int degrees, const GLuint color)
 Draws a filled Ellipse.
void glSprite (const int x, const int y, const int flipmode, const glImage *spr)
 Draws a Sprite.
void glSpriteScale (const int x, const int y, const float scale, const int flipmode, const glImage *spr)
 Draws a Scaled Sprite.
void glSpriteScaleXY (const int x, const int y, const float scaleX, const float scaleY, const int flipmode, const glImage *spr)
 Draws an Axis Exclusive Scaled Sprite.
void glSpriteRotate (const int x, const int y, const int angle, const int flipmode, const glImage *spr)
 Draws a Center Rotated Sprite.
void glSpriteRotateScale (const int x, const int y, const int angle, const float scale, const int flipmode, const glImage *spr)
 Draws a Center Rotated Scaled Sprite.
void glSpriteRotateScaleXY (const int x, const int y, const int angle, const float scaleX, const float scaleY, const int flipmode, const glImage *spr)
 Draws a Center Rotated Axis-Exclusive Scaled Sprite.
void glSpriteOnQuad (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, float uoff, float voff, int flipmode, const glImage *spr)
 Draws a Stretched Sprite across a quad
Useful for "Shrearing Effects".
void glSpriteOnQuadClipped (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, float luclip, float lvclip, float ruclip, float rvclip, int flipmode, const glImage *spr)
 Draws a Stretched Sprite across a quad with clipped textures<Br> I needed this for my ikaruga laser implementation.
void glSpriteStretchHorizontal (int x, int y, int length, const glImage *spr)
 Draws a clean horizontally stretched Sprite<Br> Useful for lasers and huds.
void glSpriteStretchVertical (int x, int y, int height, const glImage *spr)
 Draws a clean vertically stretched Sprite<Br> Useful for lasers and huds.
void glSpriteStretchHV (int x, int y, int length, int height, const glImage *spr)
 Draws a clean horizontally and vertically stretched Sprite<Br> Useful for lasers, huds and dialog boxes.
void glPrint (int x, int y, const char *text, const GLuint color)
 Prints a rudimentary text for feedback/debugging purposes<Br> Not to be used in actual application/games as it is extremely sloooow. Rasterfont from the GLRedbook.
GLuint glLoadSpriteSet (const char *filename, glImage *sprite, const int width, const int height, const int numframes, const unsigned int *texcoords, const GLuint filtermode)
 Initializes our spriteset with Texture Packer generated UV coordinates
Very safe and easy to use..
GLuint glLoadTileSet (const char *filename, glImage *sprite, const int tile_wid, const int tile_hei, const int bmp_wid, const int bmp_hei, const GLuint filtermode)
 Initializes our Tileset (like glInitSpriteset()) but without the use of Texture Packer auto-generated files.
Can only be used when tiles in a tilset are of the same dimensions.
GLuint glLoadSprite (const char *filename, glImage *sprite, const int width, const int height, const GLuint filtermode)
 Loads a single power of 2 image.
void glGet (glImage *SpriteDest, const glImage *SpriteSource, int x1, int y1, int x2, int y2)
 "Gets" a tile from a loaded spriteset.

Detailed Description

A very small and simple PC/MAC/DS rendering lib using the 3d core to render 2D stuff.

Definition in file gl2d.h.


Define Documentation

#define GL2D_RGBA (   r,
  g,
  b,
 
)    RGBA( b, g, r, a)

Macro to use for all the color arguments of Easy GL2D primitives.

Parameters:
rRed channnel of the 32 bit color (0-255).
gGreen channnel of the 32 bit color (0-255).
bBlue channnel of the 32 bit color (0-255).
aAlpha channnel of the 32 bit color (0-255).

Definition at line 71 of file gl2d.h.


Typedef Documentation

Enums selecting Blending/Blitting mode.

Enums selecting flipping mode.

These enums are bits for flipping the sprites.
You can "|" (or) GL_FLIP_V and GL_FLIP_H to flip both ways.

typedef struct glImage glImage

Struct for our GL-Based Images
This is our struct to hold our image attributes. You don't need to worry about this if you use the texture packer.

Struct for out GL-Based Images.

This is our struct to hold our image attributes.
You don't need to worry about this if you use the texture packer.


Enumeration Type Documentation

Enums selecting Blending/Blitting mode.

Enumerator:
GL2D_TRANS 

Transparent blit

GL2D_SOLID 

Solid blit

GL2D_BLENDED 

Alpha Blended blit

GL2D_GLOW 

Additive Blended blit

GL2D_ALPHA 

Alpha Transparent blit

GL2D_BLACK 

Black color blit

Definition at line 117 of file gl2d.h.

Enums selecting flipping mode.

These enums are bits for flipping the sprites.
You can "|" (or) GL_FLIP_V and GL_FLIP_H to flip both ways.

Definition at line 103 of file gl2d.h.


Function Documentation

void glBegin2D ( const int  width,
const int  height 
)

Sets up OpenGL for 2d rendering.
Call this before drawing any of GL2D's drawing or sprite functions.

Parameters:
widthwidth of the window.
heightheight of the window.

Definition at line 61 of file gl2d.c.

void glBlendMode ( const GL2D_BLEND_MODE  mode )

Sets the default blending/blitting mode.

Parameters:
modeenums for blending see example files.

Definition at line 631 of file gl2d.c.

void glBox ( int  x1,
int  y1,
int  x2,
int  y2,
const GLuint  color 
)

Draws a Box.

Parameters:
x1,y1Top-Left coordinate of the box.
x2,y2Bottom-Right coordinate of the box.
colorGL2D_RGBA color.

Definition at line 845 of file gl2d.c.

void glBoxFilled ( int  x1,
int  y1,
int  x2,
int  y2,
const GLuint  color 
)

Draws a Box filled with a single color.

Parameters:
x1,y1Top-Left coordinate of the box.
x2,y2Bottom-Right coordinate of the box.
colorGL2D_RGBA color.

Definition at line 869 of file gl2d.c.

void glBoxFilledGradient ( int  x1,
int  y1,
int  x2,
int  y2,
const GLuint  color1,
const GLuint  color2,
const GLuint  color3,
const GLuint  color4 
)

Draws a Box filled with a gradient color.

Parameters:
x1,y1Top-Left coordinate of the box.
x2,y2Bottom-Right coordinate of the box.
color1GL2D_RGBA color of the Top-Left corner.
color2GL2D_RGBA color of the Bottom-Left corner.
color3GL2D_RGBA color of the Bottom-Right corner.
color4GL2D_RGBA color of the Top-Right corner.

Definition at line 898 of file gl2d.c.

void glEllipse ( int  x,
int  y,
int  a,
int  b,
int  degrees,
const GLuint  color 
)

Draws a hollow Ellipse.

Parameters:
x,yCenter of the ellipse.
aSemi-major axis.
bSemi-minor.
degreesAngle(in degrees).
colorGL2D_RGBA color of the ellipse.

Definition at line 994 of file gl2d.c.

void glEllipseFilled ( int  x,
int  y,
int  a,
int  b,
int  degrees,
const GLuint  color 
)

Draws a filled Ellipse.

Parameters:
x,yCenter of the ellipse.
aSemi-major axis.
bSemi-minor.
degreesAngle(in degrees).
colorGL2D_RGBA color of the ellipse.

Definition at line 1060 of file gl2d.c.

void glEnableAntialias ( int  flag )

Enables or disables AA depending on the switch param flag true == enable; false(0) == disable.

Definition at line 157 of file gl2d.c.

void glEnableSpriteStencil ( const GLuint  gl2dcolor,
const GLuint  gl2dcolor_env,
int  flag 
)

Sets texture environment color Used to draw sprites in a single fill color Very useful for flash/hit animations (1 - (texture image color)) * (glColor color) + (texture image color) * (texture environment color) ie. Pure White Sprites.

Parameters:
gl2dcolorcolor.
gl2dcolor_envenvironment color.
flagtrue == blendmode; false(0) == modulate.

Definition at line 129 of file gl2d.c.

void glGet ( glImage SpriteDest,
const glImage SpriteSource,
int  x1,
int  y1,
int  x2,
int  y2 
)

"Gets" a tile from a loaded spriteset.

Parameters:
SpriteDestDestination pointer to an array of glImage.
SpriteSourceSource pointer to an array of glImage.
x1,y1Top-Left coordinate of the image to "get".
x2,y2Bottom-Right coordinate of the image to "get".

Definition at line 2088 of file gl2d.c.

void glLine ( int  x1,
int  y1,
int  x2,
int  y2,
const GLuint  color 
)

Draws a Line.

Parameters:
x1,y1Start point of the line.
y2,y2End point of the line.
colorGL2D_RGBA color.

Definition at line 805 of file gl2d.c.

void glLineGlow ( const int  x1,
const int  y1,
const int  x2,
const int  y2,
const int  width,
const GLuint  color 
)

Draws a glowing line.

Parameters:
x1,y1Start point of the line.
y2,y2End point of the line.
widthThickness of the line.
colorGL2D_RGBA color.

Definition at line 690 of file gl2d.c.

void glLineGradient ( int  x1,
int  y1,
int  x2,
int  y2,
const GLuint  color1,
const GLuint  color2 
)

Draws a Line in a gradient color.

Parameters:
x1,y1Start point of the line.
y2,y2End point of the line.
color1Start point GL2D_RGBA color .
color2End point GL2D_RGBA color .

Definition at line 825 of file gl2d.c.

GLuint glLoadSprite ( const char *  filename,
glImage sprite,
const int  width,
const int  height,
const GLuint  filtermode 
)

Loads a single power of 2 image.

Parameters:
filenamefilename of the TGA file to load ie. "ship.tga".
spritePointer to an array of glImage.
widthWidth of of the texture.
heightheight of of the texture.
filtermodeGL_NEAREST or GL_LINEAR.

Definition at line 2049 of file gl2d.c.

GLuint glLoadSpriteSet ( const char *  filename,
glImage sprite,
const int  width,
const int  height,
const int  numframes,
const unsigned int *  texcoords,
const GLuint  filtermode 
)

Initializes our spriteset with Texture Packer generated UV coordinates
Very safe and easy to use..

Parameters:
filenamefilename of the TGA file to load ie. "ships.tga".
spritePointer to an array of glImage.
widthThe horizontal size of the texture
heightThe vertical size of the texture
numframesnumber of frames in a spriteset (auto-generated by Texture Packer).
texcoordsTexture Packer auto-generated array of UV coords.
filtermodeGL_NEAREST or GL_LINEAR.

Definition at line 1941 of file gl2d.c.

GLuint glLoadTileSet ( const char *  filename,
glImage sprite,
const int  tile_wid,
const int  tile_hei,
const int  bmp_wid,
const int  bmp_hei,
const GLuint  filtermode 
)

Initializes our Tileset (like glInitSpriteset()) but without the use of Texture Packer auto-generated files.
Can only be used when tiles in a tilset are of the same dimensions.

Parameters:
filenamefilename of the TGA file to load ie. "ships.tga".
spritePointer to an array of glImage.
tile_widWidth of each tile in the texture.
tile_heiHeight of each tile in the texture.
bmp_widWidth of of the texture or tileset.
bmp_heiheight of of the texture or tileset.
filtermodeGL_NEAREST or GL_LINEAR.

Definition at line 2000 of file gl2d.c.

void glPrint ( int  x,
int  y,
const char *  text,
const GLuint  color 
)

Prints a rudimentary text for feedback/debugging purposes<Br> Not to be used in actual application/games as it is extremely sloooow. Rasterfont from the GLRedbook.

Parameters:
x,yLocation of the sprite.
texttext to print.
colorGL2D_RGBA color of the Top-Right corner.

Definition at line 1911 of file gl2d.c.

void glPutPixel ( int  x,
int  y,
const GLuint  color 
)

Draws a Pixel.

Parameters:
xX position of the pixel.
yY position of the pixel.
colorGL2D_RGBA color.

Definition at line 786 of file gl2d.c.

void glScreen2D ( const int  width,
const int  height,
const int  mode 
)

Initializes GL in 2D mode.

Parameters:
widthwidth of the window.
heightheight of the window.
modeeither GLFW_FULLSCREEN or GLFW_WINDOWED

Definition at line 503 of file gl2d.c.

void glScreen2DEx ( const int  width,
const int  height,
const int  mode,
const int  depthbits,
const int  stencilbits 
)

Initializes GL in 2D mode with more control.

Parameters:
widthwidth of the window.
heightheight of the window.
modeeither GLFW_FULLSCREEN or GLFW_WINDOWED
depthbitsdepth buffer usually 32.
stencilbitsstencil buffer 8 would suffice for most purposes.

Definition at line 510 of file gl2d.c.

void glSprite ( const int  x,
const int  y,
const int  flipmode,
const glImage spr 
)

Draws a Sprite.

Parameters:
xX position of the sprite.
yY position of the sprite.
flipmodemode for flipping (see GL2D_FLIP_MODE enum).
sprpointer to a glImage.

Definition at line 1130 of file gl2d.c.

void glSpriteOnQuad ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
int  x4,
int  y4,
float  uoff,
float  voff,
int  flipmode,
const glImage spr 
)

Draws a Stretched Sprite across a quad
Useful for "Shrearing Effects".

Parameters:
x1,y1First corner of the sprite.
x2,y2Second corner of the sprite.
x3,y3Third corner of the sprite.
x4,y4Fourth corner of the sprite.
uoff,vofftexture offsets.
flipmodemode for flipping (see GL2D_FLIP_MODE enum).
sprpointer to a glImage.

Definition at line 1448 of file gl2d.c.

void glSpriteOnQuadClipped ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
int  x4,
int  y4,
float  luclip,
float  lvclip,
float  ruclip,
float  rvclip,
int  flipmode,
const glImage spr 
)

Draws a Stretched Sprite across a quad with clipped textures<Br> I needed this for my ikaruga laser implementation.

Parameters:
x1,y1First corner of the sprite.
x2,y2Second corner of the sprite.
x3,y3Third corner of the sprite.
x4,y4Fourth corner of the sprite.
luclip,lvclipleft horizo/vertical ntaltexture offsets.
ruclip,rvclipright horizo/vertical ntaltexture offsets.
flipmodemode for flipping (see GL2D_FLIP_MODE enum).
sprpointer to a glImage.

Definition at line 1497 of file gl2d.c.

void glSpriteRotate ( const int  x,
const int  y,
const int  angle,
const int  flipmode,
const glImage spr 
)

Draws a Center Rotated Sprite.

Parameters:
xX position of the sprite center.
yY position of the sprite center.
angleAngle(in degrees) to rotate the sprite.
flipmodemode for flipping (see GL2D_FLIP_MODE enum).
sprpointer to a glImage.

Definition at line 1269 of file gl2d.c.

void glSpriteRotateScale ( const int  x,
const int  y,
const int  angle,
const float  scale,
const int  flipmode,
const glImage spr 
)

Draws a Center Rotated Scaled Sprite.

Parameters:
xX position of the sprite center.
yY position of the sprite center.
angleAngle(in degrees) to rotate the sprite.
scalescale value (1.0f is normal).
flipmodemode for flipping (see GL2D_FLIP_MODE enum).
sprpointer to a glImage.

Definition at line 1329 of file gl2d.c.

void glSpriteRotateScaleXY ( const int  x,
const int  y,
const int  angle,
const float  scaleX,
const float  scaleY,
const int  flipmode,
const glImage spr 
)

Draws a Center Rotated Axis-Exclusive Scaled Sprite.

Parameters:
xX position of the sprite center.
yY position of the sprite center.
angleAngle(in degrees) to rotate the sprite.
scaleXX-Axis scale value (1.0f is normal).
scaleYY-Axis scale value (1.0f is normal).
flipmodemode for flipping (see GL2D_FLIP_MODE enum).
sprpointer to a glImage.

Definition at line 1387 of file gl2d.c.

void glSpriteScale ( const int  x,
const int  y,
const float  scale,
const int  flipmode,
const glImage spr 
)

Draws a Scaled Sprite.

Parameters:
xX position of the sprite.
yY position of the sprite.
scalescale value (1.0f is normal).
flipmodemode for flipping (see GL2D_FLIP_MODE enum).
sprpointer to a glImage.

Definition at line 1172 of file gl2d.c.

void glSpriteScaleXY ( const int  x,
const int  y,
const float  scaleX,
const float  scaleY,
const int  flipmode,
const glImage spr 
)

Draws an Axis Exclusive Scaled Sprite.

Parameters:
xX position of the sprite.
yY position of the sprite.
scaleXX-Axis scale value (1.0f is normal).
scaleYY-Axis scale value (1.0f is normal).
flipmodemode for flipping (see GL2D_FLIP_MODE enum).
sprpointer to a glImage.

Definition at line 1221 of file gl2d.c.

void glSpriteStretchHorizontal ( int  x,
int  y,
int  length,
const glImage spr 
)

Draws a clean horizontally stretched Sprite<Br> Useful for lasers and huds.

Parameters:
x,yLocation of the sprite.
lengthlength to stretch in pixels.
sprpointer to a glImage.

Definition at line 1543 of file gl2d.c.

void glSpriteStretchHV ( int  x,
int  y,
int  length,
int  height,
const glImage spr 
)

Draws a clean horizontally and vertically stretched Sprite<Br> Useful for lasers, huds and dialog boxes.

Parameters:
x,yLocation of the sprite.
lengthlength to stretch in pixels.
heightheight to stretch in pixels.
sprpointer to a glImage.

Definition at line 1731 of file gl2d.c.

void glSpriteStretchVertical ( int  x,
int  y,
int  height,
const glImage spr 
)

Draws a clean vertically stretched Sprite<Br> Useful for lasers and huds.

Parameters:
x,yLocation of the sprite.
heightheight to stretch in pixels.
sprpointer to a glImage.

Definition at line 1636 of file gl2d.c.

void glTriangle ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
const GLuint  color 
)

Draws a Triangle.

Parameters:
x1,y1Vertex 1 of the triangle.
x2,y2Vertex 2 of the triangle.
x3,y3Vertex 3 of the triangle.
colorGL2D_RGBA color of the triangle.

Definition at line 927 of file gl2d.c.

void glTriangleFilled ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
const GLuint  color 
)

Draws a Triangle filled with a single color.

Parameters:
x1,y1Vertex 1 of the triangle.
x2,y2Vertex 2 of the triangle.
x3,y3Vertex 3 of the triangle.
colorGL2D_RGBA color of the triangle.

Definition at line 949 of file gl2d.c.

void glTriangleFilledGradient ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
const GLuint  color1,
const GLuint  color2,
const GLuint  color3 
)

Draws a Triangle filled with a gradient color.

Parameters:
x1,y1Vertex 1 of the triangle.
x2,y2Vertex 2 of the triangle.
x3,y3Vertex 3 of the triangle.
color1GL2D_RGBA color of the vertex 1.
color2GL2D_RGBA color of the vertex 2.
color3GL2D_RGBA color of the vertex 3.

Definition at line 971 of file gl2d.c.